﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;

namespace Najak
{
	public static partial class MathUtil
	{
		static public int FindDistanceSquared(Point p1, Point p2)
		{
			int dx = p1.X - p2.X;
			int dy = p1.Y - p2.Y;
			int dist2 = (dx * dx) + (dy * dy);
			return dist2;
		}

		static public float GetRotation(Vector2 offset)
		{
			float ratio = offset.Y / offset.X;

			float rotation = (float)Math.Atan(ratio);

			if (offset.X < 0)
				rotation += (float)Math.PI;

			rotation += 0.5f * (float)Math.PI;
			return rotation;
		}

		static public Vector2 ConvertRotationToOffset(float rotation)
		{
			Vector3 offset = new Vector3(0, 1, 0);
			Quaternion rot = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, rotation);
			offset = Vector3.Transform(offset, rot);
			return new Vector2(offset.X, offset.Y);
		}

		static public Vector2 RotateVector(Vector2 baseOffset, float rotation)
		{
			Vector3 offset = new Vector3(baseOffset, 0);
			Quaternion rot = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, rotation);
			offset = Vector3.Transform(offset, rot);
			return new Vector2(offset.X, offset.Y);
		}

	}
}
